package edu.bbu.commonproject.backend.db.factory.mongodb;

import java.net.UnknownHostException;
import java.util.logging.Level;

import com.mongodb.DB;
import com.mongodb.DBObject;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;

import edu.bbu.commonproject.backend.db.factory.DAOFactory;
import edu.bbu.commonproject.backend.db.services.DirectoryDAOServices;
import edu.bbu.commonproject.backend.db.services.FileDAOServices;
import edu.bbu.commonproject.backend.db.services.UserDAOServices;
import edu.bbu.commonproject.backend.db.services.mongodb.MongoDBDirectoryDAOService;
import edu.bbu.commonproject.backend.db.services.mongodb.MongoDBFileDAOServices;
import edu.bbu.commonproject.backend.db.services.mongodb.MongoDBUserDAOServices;
import edu.bbu.commonproject.backend.utils.ServerLogger;
import edu.bbu.commonproject.backend.utils.SystemConfig;

/**
 * The MongoDB DAO factory. 
 */
public class MongoDBDAOFactory extends DAOFactory
{
	/** The database. */
	public static DB dataBase = null;
	
	/** The mongoDB user DAO services. */
	private MongoDBUserDAOServices mongoDBUserDAOServices;
	
	/** The mongoDB file DAO services. */
	private MongoDBFileDAOServices mongoDBFileDAOServices;
	
	/** The mongoDB directory DAO services. */
	private MongoDBDirectoryDAOService mongoDBDirectoryDAOService;
	
	/**
	 * The constructor.
	 */
	public MongoDBDAOFactory()
	{
		try
		{
			MongoClient mongoConnection = new MongoClient(SystemConfig.getValue(SystemConfig.MONGO_HOST_ADRESS), Integer.parseInt(SystemConfig.getValue(SystemConfig.MONGO_HOST_PORT)));
			dataBase = mongoConnection.getDB("FileSharingDB");
			
			mongoDBUserDAOServices = new MongoDBUserDAOServices();
			mongoDBFileDAOServices = new MongoDBFileDAOServices();
			mongoDBDirectoryDAOService = new MongoDBDirectoryDAOService();
		}
		catch (UnknownHostException e)
		{
			ServerLogger.log(Level.SEVERE, "Unknown mongoDB host.");
		}
	}
	
	/**
	 * Getting the User services.
	 */
	public UserDAOServices getUserDAOServices()
	{
		return mongoDBUserDAOServices;
	}
	
	/**
	 * Getting the file services. 
	 */
	public FileDAOServices getFileDAOServices()
	{
		return mongoDBFileDAOServices;
	}
	
	/**
	 * Getting the directory services.
	 */
	public DirectoryDAOServices getDirectoryServices()
	{
		return mongoDBDirectoryDAOService;
	}
}
